package com.example.gridview_demo;

import android.os.Bundle;
import android.widget.GridView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private GridView gridview;
    private List<Gridview_mode> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        inifunction();
    }

    private void initView() {
        gridview = (GridView) findViewById(R.id.gridview);
    }
    private void inifunction() {
        list=new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            list.add(new Gridview_mode(R.drawable.ic_launcher_background,"标题："+i));
        }
        Gridview_Adapter adapter=new Gridview_Adapter(list,this);
        gridview.setAdapter(adapter);
    }
}